package com.mxy.batterychargingreminding;

import android.app.Application;
import android.content.res.Configuration;
import android.content.res.Resources;

import com.tencent.bugly.crashreport.CrashReport;

/**
 * Application
 *
 * @author 马晓勇
 */

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        String processName = Util.getProcessName(this, android.os.Process.myPid());
        if (processName == null) {
            processName = "abc";
        }
        //根据进程名进行初始化，避免不同的进程导致的多次初始化
        if (processName.equals(this.getPackageName())) {
            Util.isDebugMode(this);
            CrashReport.initCrashReport(getApplicationContext(), "e0233a07dc", false);
        }
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        //非默认值
        if (newConfig.fontScale != 1) {
            //发现字体变化之后，调用getResources()方法重新设置字体
            getResources();
        }
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        //非默认值
        if (res.getConfiguration().fontScale != 1) {
            Configuration newConfig = new Configuration();
            //设置默认
            newConfig.setToDefaults();
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
    }
}